package com.feisuanyz.lyweb01.service.impl;

import com.feisuanyz.lyweb01.dao.AboutUsMapper;
import com.feisuanyz.lyweb01.pojo.domain.AboutUsDO;
import com.feisuanyz.lyweb01.pojo.dto.AboutUsUpdateDTO;
import com.feisuanyz.lyweb01.service.AboutUsService;
import java.lang.Boolean;
import java.lang.Override;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.feisuanyz.lyweb01.exception.BusinessException;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import java.util.Map;
import com.feisuanyz.lyweb01.constant.ResultCodeConstant;

/**
 * AboutUsServiceImpl
 *
 * @author deng
 * @date 2025-02-26 11:57:37
 */
@Service
public class AboutUsServiceImpl implements AboutUsService {

    @Autowired
    private AboutUsMapper aboutUsMapper;

    @Override
    public AboutUsDO getAboutUsInfo() {
        QueryWrapper<AboutUsDO> queryWrapper = Wrappers.emptyWrapper();
        AboutUsDO aboutUsDO = aboutUsMapper.selectOne(queryWrapper);
        if (aboutUsDO != null) {
            return aboutUsDO;
        } else {
            throw new BusinessException(ResultCodeConstant.CODE_000001, ResultCodeConstant.CODE_000001_MSG);
        }
    }

    @Override
    public Boolean updateAboutUsInfo(AboutUsUpdateDTO aboutUsUpdateDTO) {
        QueryWrapper<AboutUsDO> queryWrapper = new QueryWrapper<>();
        AboutUsDO aboutUsDO = new AboutUsDO();
        aboutUsDO.setAboutUsId(aboutUsUpdateDTO.getAboutUsId());
        queryWrapper.setEntity(aboutUsDO);
        aboutUsDO = aboutUsMapper.selectOne(queryWrapper);
        if (aboutUsDO != null) {
            aboutUsDO.setCompanyProfile(aboutUsUpdateDTO.getCompanyProfile());
            aboutUsDO.setTeamIntroduction(aboutUsUpdateDTO.getTeamIntroduction());
            int result = aboutUsMapper.updateById(aboutUsDO);
            if (result > 0) {
                return true;
            } else {
                throw new BusinessException(ResultCodeConstant.CODE_999999, ResultCodeConstant.CODE_999999_MSG);
            }
        } else {
            throw new BusinessException(ResultCodeConstant.CODE_000001, ResultCodeConstant.CODE_000001_MSG);
        }
    }
}
